package vn.bk.hotel.global;

import java.util.Locale;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import hust.sig.api.service.ImplementHotelService;

public class Language {

    public static final String VI = ImplementHotelService.VIETNAMESE;
    public static final String EN = ImplementHotelService.ENGLISH;
    private static String data, myLanguage;
    public static boolean reload = false;

    private static SharedPreferences myPreference;

    public static void setLanguage(Context mContext, String language) {
	Editor edit = getInstance(mContext).edit();
	edit.putString(myLanguage, language);
	edit.commit();
    }

    public static String getLanguage(Context mContext) {
	return getInstance(mContext).getString(myLanguage, VI);
    }

    private static SharedPreferences getInstance(Context mContext) {
	if (myPreference == null) {
	    myPreference = mContext.getSharedPreferences(data, 0);
	}
	return myPreference;
    }

    public static void applySettingLanguage(Activity mContext) {
	Locale locale;
	if (Language.getLanguage(mContext) == Language.EN) {
	    locale = new Locale("en_US");
	} else {
	    locale = new Locale("vi");
	}
	Locale.setDefault(locale);
	Configuration config = new Configuration();
	config.locale = locale;	
	mContext.getResources().updateConfiguration(config, null);
	if(reload){	
	    mContext.finish();
	    mContext.startActivity(new Intent(mContext, mContext.getClass()));
	    reload = false;
	}
    }

}
